/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.controller;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.cmcc.zysoft.infocollection.common.BaseController;
import com.cmcc.zysoft.infocollection.model.News;
import com.cmcc.zysoft.infocollection.model.SystemUser;
import com.cmcc.zysoft.infocollection.service.LoginOutLogPcService;
import com.cmcc.zysoft.infocollection.service.NewsPcService;
import com.cmcc.zysoft.infocollection.service.ResourcePcService;
import com.cmcc.zysoft.spring.security.util.SecurityContextUtil;
import com.cmcc.zysoft.sysmanage.service.SystemUserPCService;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: IndexController.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-9-10 上午9:32:12
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Controller
@RequestMapping("/")
public class IndexController extends BaseController {
	
	/**
	 * 日志.
	 */
	private static Logger _logger = LoggerFactory.getLogger(IndexController.class);
	
	private static final String INDEX_VIEW = "/index";
	
	private static final String HOME_VIEW = "/pc/home/index";
	
	/**
	 * 属性名称: newsPcService.
	 * 类       型: NewsPcService.
	 */
	@Resource
	private NewsPcService newsPcService;
	
	/**
	 * 属性名称: resourcePcService.
	 * 类       型: ResourcePcService.
	 */
	@Resource
	private ResourcePcService resourcePcService;
	
	/**
	 * 属性名称: systemUserPcService.
	 * 类       型: SystemUserPcService.
	 */
	@Resource
	private SystemUserPCService systemUserPcService;
	
	/**
	 * 属性名称: loginOutLogPcService.
	 * 类       型: LoginOutLogPcService.
	 */
	@Resource
	private LoginOutLogPcService loginOutLogPcService;
	
	/**
	 * 跳转到首页.
	 * @return ModelAndView
	 */
	@RequestMapping("index.htm")
	public ModelAndView index() {
		_logger.debug("#跳转到首页");
		ModelAndView modelAndView = new ModelAndView(INDEX_VIEW);
		return modelAndView;
	}
	
	/**
	 * 跳转到home页面.
	 * @param modelMap modelMap
	 * @return String
	 */
	@RequestMapping("home.htm")
	public String home(ModelMap modelMap) {
		_logger.debug("#跳转到home页面");
		String companyId = SecurityContextUtil.getCompanyId();
		//首页-通知公告.
		List<Map<String, Object>> newsList = this.newsPcService.news(companyId);
		//首页-最新动态.
		List<Map<String, Object>> dynamicList = this.loginOutLogPcService.latestDynamic(companyId);
		//每月采集和更新商户信息统计.
		String infoAnalyze = this.resourcePcService.infoAnalyze();
		//各地市商户信息采集情况汇总.
		String infoSumAnalyze = this.resourcePcService.infoSumAnalyze();
		modelMap.put("data1", infoAnalyze);
		modelMap.put("data2", infoSumAnalyze);
		modelMap.addAttribute("newsList", newsList);
		modelMap.addAttribute("dynamicList", dynamicList);
		return HOME_VIEW;
	}
	
	/**
	 * 查看信息公告详情.
	 * @param modelMap modelMap
	 * @param newsId 信息公告ID
	 * @return String
	 */
	@RequestMapping("detail.htm")
	public String detail(ModelMap modelMap, String newsId) {
		News news = this.newsPcService.getEntity(newsId);
		SystemUser systemUser = this.systemUserPcService.getEntity(news.getPublishMan());
		modelMap.addAttribute("news", news);
		modelMap.addAttribute("userName", systemUser.getRealName());
		return "/pc/home/newsDetail";
	}
}